/*
 * CheckLoginAdminBO
 * Version: 1.0
 * Date: 28/07/2014
 * 
 * Copyright: ThoNQ
 * 
 * Modification Logs:
 * DATE             AUTHOR              DESCRIPTION
 * ==================================================
 * 24/07/2014       ThoNQ               Create
 */

package model.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class CheckLoginAdminDAO extends BaseDAO{
    
    Connection connection = null;

    public boolean isValid(String userName, String password) {
        
    	connection = getConnection();
        String sqlCheckLogin = "SELECT TenTaiKhoan FROM TAIKHOAN WHERE TenTaiKhoan = ? AND MatKhau = ?";
        boolean privilege = false;
        
        if(connection != null){
            try{
               PreparedStatement pstm = connection.prepareStatement(sqlCheckLogin);
               pstm.setString(1, userName);
               pstm.setString(2, password);
               ResultSet result = pstm.executeQuery();
               if(result.next()){
            	   privilege = true;
               }
               return privilege;
            } catch (SQLException e) {
                e.printStackTrace();
                return privilege;
            }finally{
                closeConnection();
            }
        }else{
            // do not something
        }
        return privilege;
    }

}
